package model;

import java.io.Serializable;
import javax.persistence.*;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;


/**
 * The persistent class for the task database table.
 * 
 */
@Entity
public class Task implements Serializable {

	
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="task_id")
	private int taskId;

	private boolean active;

	private String description;

	private BigDecimal price;

    @Temporal( TemporalType.TIMESTAMP)
	@Column(name="start_time")
	private Date startTime = new Date();

	@Column(name="status_code")
	private String statusCode;

    @Temporal( TemporalType.TIMESTAMP)
	@Column(name="stop_time")
	private Date stopTime;

	@Column(name="unit_code")
	private String unitCode;

	private int workhours;

	//bi-directional many-to-one association to Servicecall
    @ManyToOne
	@JoinColumn(name="servicecall_id")
	private ServiceCall servicecall;

	//bi-directional many-to-one association to Operator
    @ManyToOne
	@JoinColumn(name="operator_id")
	private Operator operator;

	//bi-directional many-to-one association to Taskproduct
	@OneToMany(mappedBy="task")
	private Set<Taskproduct> taskproducts;

    public Task() {
    }

	public int getTaskId() {
		return this.taskId;
	}

	public void setTaskId(int taskId) {
		this.taskId = taskId;
	}

	public boolean isActive() {
		return this.active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public Date getStartTime() {
		return this.startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public String getStatusCode() {
		return this.statusCode;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public Date getStopTime() {
		return this.stopTime;
	}

	public void setStopTime(Date stopTime) {
		this.stopTime = stopTime;
	}
	
	public void setStopTimeString(String stopTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
		try {
			setStopTime(sdf.parse(stopTime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String getStartTimeString(){
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
		return sdf.format(getStartTime());
	}
	
	public void setStartTimeString(String startTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
		try {
			setStartTime(sdf.parse(startTime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String getStopTimeString(){
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
		return sdf.format(getStopTime());
	}

	public String getUnitCode() {
		return this.unitCode;
	}

	public void setUnitCode(String unitCode) {
		this.unitCode = unitCode;
	}

	public int getWorkhours() {
		return this.workhours;
	}

	public void setWorkhours(int workhours) {
		this.workhours = workhours;
	}

	
	public ServiceCall getServicecall() {
		return servicecall;
	}

	public void setServicecall(ServiceCall servicecall) {
		this.servicecall = servicecall;
	}

	public Operator getOperator() {
		return this.operator;
	}

	public void setOperator(Operator operator) {
		this.operator = operator;
	}
	
	public Set<Taskproduct> getTaskproducts() {
		return this.taskproducts;
	}

	public void setTaskproducts(Set<Taskproduct> taskproducts) {
		this.taskproducts = taskproducts;
	}
	
	
	
}